#include <gtest/gtest.h>
#include "ECS/Signals.h"

TEST(Signals, ConnectAndCall)
{
	Signal<void()> event1;
	int a = 1;
	int* pa = &a;
	Connection c = event1.connect([pa]() -> void {*pa = 2;});
	event1();
	EXPECT_EQ(a, 2);
}

TEST(Signals, DisconnectAndCall)
{
	Signal<void()> event1;
	int a = 1;
	int* pa = &a;
	Connection c = event1.connect([pa]() -> void {*pa = 2;});
	c.disconnect();
	event1();
	EXPECT_EQ(a, 1);
}

TEST(Signals, DisconnectConnectAndCall)
{
	Signal<void()> event1;
	int a = 1;
	int* pa = &a;
	Connection c = event1.connect([pa]() -> void {*pa = 2;});
	c.disconnect();
	c.connect();
	event1();
	EXPECT_EQ(a, 2);
}

TEST(Signals, IsAlive)
{
	auto event1 = new Signal<void()>();
	int a = 1;
	int* pa = &a;
	Connection c = event1->connect([pa]() -> void {*pa = 2;});
	EXPECT_EQ(c.isConnected(), true);
	delete event1;
	EXPECT_EQ(c.isConnected(), false);
}